package org.yn.base.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.yn.exception.ResponseCode;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class AjaxResult {
    // 返回响应码的
    private Integer code;
    // 存数据的
    private Object resultObj;
    // 标识符
    private Boolean success;
    // 提示信息
    private String msg;

    public static AjaxResult success(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(true);
        ajaxResult.setMsg(ResponseCode.RESPONSE_CODE_200.getMessage());
        ajaxResult.setCode(ResponseCode.RESPONSE_CODE_200.getCode());
        return ajaxResult;
    }
//    public static AjaxResult success(String msg){
//        AjaxResult ajaxResult = new AjaxResult();
//        ajaxResult.setSuccess(true);
//        ajaxResult.setMsg(msg);
//        ajaxResult.setCode(ResponseCode.RESPONSE_CODE_200.getCode());
//        return ajaxResult;
//    }
    public static AjaxResult success(Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(true);
        ajaxResult.setMsg(ResponseCode.RESPONSE_CODE_200.getMessage());
        ajaxResult.setCode(ResponseCode.RESPONSE_CODE_200.getCode());
        ajaxResult.setResultObj(data);
        return ajaxResult;
    }
    public static AjaxResult error(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg("失败");
        return ajaxResult;
    }
    public static AjaxResult error(String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }
    public static AjaxResult error(String msg,Integer code){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg(msg);
        ajaxResult.setCode(code);
        return ajaxResult;
    }
}